package phoeics.authoryserver.webservice.entity.listener;

import javax.persistence.PrePersist;

//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import phoeics.authoryserver.SpringContextUtils;
import phoeics.authoryserver.webservice.entity.OauthUser;
//@Component
public class OauthUserListener {
	//private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(OauthUserListener.class);
	//@Autowired
	//private PasswordEncoder passwordEncoder;
	@PrePersist
    public void postPersist(Object entity) {
		if(entity.getClass() == OauthUser.class){
			PasswordEncoder passwordEncoder=SpringContextUtils.getBeanById("passwordEncoder",PasswordEncoder.class);
			OauthUser user=(OauthUser)entity;
			String password=user.getPassword();
			user.setPassword(passwordEncoder.encode(password));
		}
	}
}
